import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.*;
import java.util.Date;

public class SwingLayoutTest {
    private static final int screenWidth;
    private static final int screenHeight;

    static {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        screenWidth = screenSize.width;
        screenHeight = screenSize.height;
    }

    public static void main(String[] args) throws Exception {
        JFrame mainWindow = new JFrame();
        mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        mainWindow.setSize(screenWidth, screenHeight);
        mainWindow.setExtendedState(JFrame.MAXIMIZED_BOTH);
        Container contentPane = mainWindow.getContentPane();
        contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.X_AXIS));
        JTree tree = createTree();
        //tree.setPreferredSize(new Dimension(screenWidth/2, screenHeight));
        JScrollPane scrollTree = new JScrollPane(tree);
        JTable table = createTable();
        //table.setPreferredSize(new Dimension(screenWidth/2, screenHeight));
        table.getColumnModel().getColumn(1).setMaxWidth(150);
        table.getColumnModel().getColumn(2).setMaxWidth(200);
        table.getColumnModel().getColumn(1).setMinWidth(150);
        table.getColumnModel().getColumn(2).setMinWidth(200);
        JScrollPane scrollTable = new JScrollPane(table);
        JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scrollTree, scrollTable);
        splitPane.setDividerLocation(screenWidth/2);
        splitPane.setResizeWeight(0.5);
        contentPane.add(splitPane);
        table.getColumnModel().getColumn(1).setWidth(100);
        table.getColumnModel().getColumn(2).setWidth(100);
        mainWindow.setVisible(true);
        table.getColumnModel().getColumn(1).setWidth(100);
        table.getColumnModel().getColumn(2).setWidth(100);

    }

    private static JTree createTree(){
        DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("This is root Node");
        DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("Child 1");
        rootNode.add(child1);
        child1.add(new DefaultMutableTreeNode("Child 1 1"));
        child1.add(new DefaultMutableTreeNode("Child 1 2"));
        DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("Child 2");
        rootNode.add(child2);
        child2.add(new DefaultMutableTreeNode("Child 2 1"));
        child2.add(new DefaultMutableTreeNode("Child 2 2"));
        return new JTree(rootNode);
    }

    private static JTable createTable(){
        String[] columnNames = {"Name", "Size", "Modified Time"};
        Object[][] data = {{"This is row 1","1000", new Date()},
                {"This is row 2", "5455", new Date()}};
        return new JTable(data, columnNames);
    }
}
